﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EmoneyWeiXinEntity;
using EmoneyWeiXinCommon;
using System.Data.SqlClient;
using System.Data;
namespace EmoneyWeiXinDAL
{
    public class KeyWordManagerDal
    {
        public static List<KeyWordManagerEntity> getKeyWordManagerList(int pindex, int psize, int weixinid, out int total)
        {
            SqlParameter[] parameters = new SqlParameter[] {
            new SqlParameter("@pindex",pindex),
            new SqlParameter("@psize", psize),
            new SqlParameter("@total",0),
            new SqlParameter("@weixinid",weixinid)
            };
            parameters[2].Direction = ParameterDirection.Output;
            List<KeyWordManagerEntity> result = SQLHelper.GetProcedureDataByColumnsLst<KeyWordManagerEntity>(Config.EmoneyWeiXin, "sp_KeyWordManager_Select", parameters);
            total = Convert.ToInt32(parameters[2].Value);
            return result;
        }
        public static List<KeyWordManagerEntity> getKeyWordManagerListByID(int id)
        {
            SqlParameter[] parameters = new SqlParameter[] {
            new SqlParameter("@id",id)
            };
            List<KeyWordManagerEntity> result = SQLHelper.GetProcedureDataByColumnsLst<KeyWordManagerEntity>(Config.EmoneyWeiXin, "sp_KeyWordManager_SelectByID", parameters);
            return result;
        }
        public static DataSet getKeyWordManager_NewsReportListByID(int id)
        {
            SqlParameter[] parameters = new SqlParameter[] {
            new SqlParameter("@id",id)
            };
            DataSet result = SQLHelper.ExecuteGetDataSet(Config.EmoneyWeiXin, CommandType.StoredProcedure, "sp_KeyWordManager_NewsReport_List", parameters);
            return result;
        }
        public static int UpdateKeyWordManager(KeyWordManagerEntity obj, string newsreportids)
        {
            SqlParameter[] parameters = new SqlParameter[] {
            new SqlParameter("@id" , obj.id),
            new SqlParameter("@weixinid" , obj.weixinid),
            new SqlParameter("@keyword", obj.keyword),
            new SqlParameter("@replyContent", obj.replyContent),
            new SqlParameter("@isvalid", obj.isvalid),
            new SqlParameter("@isdel", obj.isdel),
            new SqlParameter("@validStartTime", obj.validStartTime),
            new SqlParameter("@validEndTime", obj.validEndTime),
            new SqlParameter("@isLongValid", obj.isLongValid),
            new SqlParameter("@createtime", obj.createtime),
            new SqlParameter("@updatetime", obj.updatetime),
            new SqlParameter("@newsreportids", newsreportids)
            };
            int result = SQLHelper.ExecuteNonQuery(Config.EmoneyWeiXin, CommandType.StoredProcedure, "sp_KeyWordManager_Update", parameters);
            return result;
        }
        public static int DeleteKeyWordManager(int id)
        {
            SqlParameter[] parameters = new SqlParameter[] {  
            new SqlParameter("@id", id)};
            int result = SQLHelper.ExecuteNonQuery(Config.EmoneyWeiXin, CommandType.StoredProcedure, "sp_KeyWordManager_Delete", parameters);
            return result;
        }
    }
}
